package efr.servlet;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

import efr.dao.ComentariuDao;
import efr.dao.impl.ComentariuDaoImpl;
import efr.entity.Comentariu;

/**
 * Servlet implementation class Op4ComentariuSubmitServlet
 */
public class Op4ComentariuSubmitServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private static Logger logger = Logger.getLogger(Op4ComentariuSubmitServlet.class);
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Op4ComentariuSubmitServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		logger.debug("start doGet()");
		if("Modifica".equals(request.getParameter("action"))){
			String id = request.getParameter("id");
			String status = request.getParameter("status");
			
//			Comentariu comentariu = new Comentariu();
//			comentariu.setId(Integer.valueOf(id));
//			comentariu.setStatus(status);
			
			ComentariuDao comentariuDao = new ComentariuDaoImpl();
			Comentariu comentariu = comentariuDao.getComentariu(Integer.valueOf(id));
			comentariu.setStatus(status);
			comentariuDao.updateComentariu(comentariu);
			
		}
		
		if("Adauga".equals(request.getParameter("action"))){
//			String titlu = request.getParameter("titlu");
//			String idAutor = request.getParameter("autor");
//			String versuri = request.getParameter("versuri");
//			String date = request.getParameter("date");
//			String poezieDefault = request.getParameter("poezieDefault");
//			String numeFile = request.getParameter("numeFile");
//			String idYtb = request.getParameter("idYtb");
			
//			Comentariu poezie = new Comentariu();
//			poezie.setTitlu(titlu);
//			poezie.setVersuri(versuri);
//			poezie.setIdYtb(idYtb);
//			poezie.setNumeFile(numeFile);
//			poezie.setComentariuDefault(Integer.valueOf(poezieDefault));
//			poezie.setDate(EfrAdmUtil.convertStringToDate(date, "yyyy-MM-dd HH:mm:ss.S"));//2013-07-07 17:55:32.0
//			
//			AutorDao autorDao = new AutorDaoImpl();
//			Autor autor = autorDao.getAutor(Integer.valueOf(idAutor));	
//			poezie.setAutor(autor);
//			
//			ComentariuDao poezieDao = new ComentariuDaoImpl();
//			poezieDao.addComentariu(poezie);
			
		}
		
		RequestDispatcher view = request.getRequestDispatcher("/ListComentarii.do");
		logger.debug("end doGet()");
		view.forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
